{include file="admin@public/header"/}

<link rel="stylesheet" href="/public/static/admin/css/report.css" />
<link rel="stylesheet" href="/public/static/admin/easyui/layui-v2.6.8/css/layui.css">
<!-- <link rel="stylesheet" type="text/css" href="/public/static/admin/easyui/jeasyui/themes/icon.css"> -->
<style>
	.ui-icon-ellipsis {
		right: 5px;
	}

	#filter-menu .con {
		width: 355px;
	}

	#filter-menu label.tit {
		width: 80px;
	}

	/*.ui-jqgrid tr.jqgrow td {
	white-space: normal !important;
	}
	*/
	.no-query {
		background: url("/public/static/admin/css/img/no_query.png") no-repeat scroll 100px 60px #fff;
		background-position: center;
		border: 1px solid #ddd;
		border-top: none;
		height: 402px;
		margin-right: 0;
	}

	.box-flex {
		overflow: hidden;
		zoom: 1;
	}

	.box-flex .flex {
		float: left;
		width: 33.3%;
	}

	.grid-title {
		font-size: 24px;
		text-align: center;
		clear: none;
	}

	.ui-print .grid-wrap {
		padding: 20px 0 0 30px;
	}

	#conditions-trigger {
		background: url(/public/static/admin/css/img/bg.png) no-repeat;
		border: 0px;
		width: 74px;
		box-shadow: 0px 0px;
	}

	#filter-menu .conditions-trigger>b {
		position: absolute;
		right: 0;
		top: 50%;
		margin-top: -8px;
		width: 16px;
		height: 16px;
		background: url(/public/static/admin/css/img/down.png) 2px 5px no-repeat;
	}

	#filter-menu .conditions-trigger>b.act {
		background: url(/public/static/admin/css/img/up.png) 2px 5px no-repeat;
	}

	#filter-menu .btns {
		position: absolute;
		top: 7px;
		right: 0px;
	}

	.layui-form-checkbox[lay-skin=primary] i {
		padding: 0;
	}

	.layui-form-checked[lay-skin=primary] i {
		border-color: #5dc5e7;
		background-color: #5dc5e7;
		color: #fff;
		padding: 0;
	}

	.layui-form-checkbox[lay-skin=primary]:hover i {
		border-color: #5dc5e7;
	}

	.ui-droplist-wrap {
		height: auto;
	}

	#filterItems {
		height: auto;
	}
    .ul-inline li{margin-right: 14px;}
    .layui-form-checkbox[lay-skin=primary] span{padding-right: 12px;}
    .layui-form-checkbox span{font-size: 12px;}
    .layui-form-checkbox[lay-skin=primary]{padding-left: 22px;}
</style>

<div class="wrapper">
	<!-- header -->
	<div class="mod-search cf">
		<div class="l  layui-form" id="filter-menu">
			<ul class="ul-inline fix" id="filterItems" style="height: 44px;font-size: 12px;">
				<li id="date" style="display: list-item;"><label>单据日期:</label>
					<input type="date" id="startdate" class="ui-input " value="" style="width: 125px;">
					<span class="todate"> 至 </span>
					<input type="date" id="enddate" class="ui-input " value="" style="width: 125px;">
				</li>
				<!-- 选择仓库 -->
				{include file="admin@select/store"/}

                <!-- 选择商品 -->
				{include file="admin@select/goods"/}

                <!-- 选择商品类别 -->
				{include file="admin@select/goods_category"/}

                <li id="" style="display: list-item;padding-top: 11px;">
					<input type="checkbox" name="status" id="chk-ischecked" lay-skin="primary" title="无发生额不显示" value="0">
				</li>
				<li id="" style="display: list-item;padding-top: 11px;">
					<label>业务类别:</label>
					<input type="checkbox" name="transType" id="transType1" lay-skin="primary" title="普通采购" value="0" >
					<input type="checkbox" name="transType" id="transType2" lay-skin="primary" title="采购退回" value="1">
					<input type="checkbox" name="transType" id="transType3" lay-skin="primary" title="普通销售" value="2">
					<input type="checkbox" name="transType" id="transType4" lay-skin="primary" title="销售退回" value="3">
					<input type="checkbox" name="transType" id="transType5" lay-skin="primary" title="其他入库" value="4">
					<input type="checkbox" name="transType" id="transType6" lay-skin="primary" title="其他出库" value="5">
					<input type="checkbox" name="transType" id="transType7" lay-skin="primary" title="调拨单" value="6">
					<input type="checkbox" name="transType" id="transType8" lay-skin="primary" title="组装单" value="7">
					<input type="checkbox" name="transType" id="transType9" lay-skin="primary" title="拆卸单" value="8">
				</li>


				<div class="btns" style="top:0;"><a class="ui-btn mrb ui-btn-search" id="filter-submit">查询</a></div>
				<!-- <span class="url-box" id="openUrl"><a href="https://club.kingdee.com/club/newclub/school/course?product_id=7&amp;cid=1548#pid=5713" target="_blank" class="video-icon" style="margin-right: 5px;"></a>功能简介</span> -->
			</ul>
			<a href="#" id="conditions-trigger" class="ui-btn conditions-trigger" tabindex="-1">&nbsp;更多条件<b></b></a>
		</div>
	</div>

	<!-- 下拉树选择（商品类别） -->
	{include file="admin@popup/goods_category"/}

	<!-- no data -->
	<div class="no-query"></div>
	<!-- grid begin -->
	<div class="ui-print" id="ui-print" style="visibility: hidden;">
		<!-- 列配置 -->
		<div class="cf box-flex">
			<div class="flex">
				<span id="config" class="ui-config"><a href="#" class="ui-icon-config-new"></a>列设置</span>
			</div>

			<div class="grid-title flex">商品收发明细表</div>
			<div class="fr">
				<a href="#" class="ui-btn ui-btn-export btn-sm mrb fl" id="btn-export">导出</a>
			</div>
		</div>

		<div class="grid-wrap" id="grid-wrap" style="padding-bottom: 30px;padding-right: 30px;">
			<!--startprint-->
			<!-- <div class="grid-title">商品收发明细表</div> -->
			<div class="grid-subtitle"></div>
			<table id="grid"></table>
			<!--endprint-->
			<div id="page"></div>
		</div>
	</div>
	<!-- grid end -->

	<!--  以隐藏的方式获取商品的样式 ，作用是赋值 -->
	<div style="display:none;">

		<input type="text" id="supplierid" value="" autocomplete="off" readonly="">
		<input type="text" id="goodsid" value="" autocomplete="off" readonly="">
		<input type="text" id="storeid" value="" autocomplete="off" readonly="">
	</div>
</div>

<script type="text/javascript" src="/public/static/admin/easyui/jeasyui/jquery.easyui.min.js"></script>
<script type="text/javascript">
	function preview(oper) {
		if (oper < 10) {
			$("#grid-wrap").jqprint();
		} else {
			window.print();
		}
	}
</script>


<script type="text/javascript">

	$(document).ready(function () {
        layui.use(['form', 'layer', 'jquery' ], function () {
            // $ = layui.jquery;
            var layer = layui.layer,
                form = layui.form;
            //监听多选框点击事件  主要是通过 lay-filter="chkStock"  来监听
            form.on('checkbox(chkStock)', function (data) {
            // 　　console.log( data );　　//打印当前选择的信息
                if( data.elem.checked){　　　　　　//判断当前多选框是选中还是取消选中
                    // alert('当前选中');
                    $("#chk-ischecked-li").show();
                }else{
                    $("#chk-ischecked-li").hide();
                }
            // 　　var value = data.value;   //获取选中的value值
            });
        });


		// 点击查询按钮
		$("#filter-submit").click(function () {
			$("#ui-print").css({ "visibility": "visible" });  //显示表格数据
			$(".no-query").hide();  //隐藏提示

			// 设置表格高度
			$("#grid").setGridHeight($(window).height()-260-$("#filter-menu").height()+"px");

			var startdate=$("#startdate").val();
			var enddate=$("#enddate").val();
            

			$("div.grid-subtitle").text("日期: "+startdate+" 至 "+enddate);

			//此处可以添加对查询数据的合法验证 
			$("#grid").jqGrid('setGridParam', {
				datatype: 'json',
				postData: { 'ajax': '100'}, //发送数据 
				page: 1
			}).trigger("reloadGrid"); //重新载入 
		});



		//alert("1111");
		$("#grid").jqGrid({
			url: '/store/goodsflowdetail/index.html?ajax=100',
			datatype: "json",//数据来源，本地数据（local，json,jsonp,xml等）
			height: '90%',//高度，表格高度。可为数值、百分比或'auto'
			width: '100%',
			//width: Public.setGrid().w,
			//height: Public.setGrid().h,
			colNames: ["id", "商品类别", "商品编号", "商品名称", "商品条码", "规格型号", "商品备注", "日期", "单据号", "业务类别", "往来单位", "仓库", "单位", "备注", "入库数量", "基本单位数量", "单位成本", "成本", "出库数量", "基本单位数量", "单位成本", "成本", "基本单位数量", "单位成本", "成本"],
			colModel: [
				{ name: 'id', index: 'id', width: 80, label: "id", hidden: true },
				{ name: 'goods_category_name', index: '', width: 85, label: "商品类别" },
				{ name: 'sn', index: '', width: 85, label: "商品编号" },
				{ name: 'name', index: '', width: 205, label: "商品名称" },
                { name: 'code', index: '', width: 125, label: "商品条码", align:"center" },
				{ name: 'model', index: '', width: 65, label: "规格型号" },
				{ name: '', index: '', width: 55, label: "商品备注" },
				{ name: '', index: '', width: 85, label: "日期" },
				{ name: '', index: '', width: 125, label: "单据号" },
				{ name: '', index: '', width: 65, label: "业务类别" },
				{ name: '', index: '', width: 105, label: "往来单位" },
				{ name: '', index: '', width: 65, label: "仓库" },
				{ name: '', index: '', width: 65, label: "单位" },
				{ name: '', index: '', width: 65, label: "备注" },
				{ name: 'rk_num', index: '', width: 85, label: "入库数量", align:"center" },
				{ name: '', index: '', width: 85, label: "基本单位数量", align:"center" },
				{ name: 'rk_price', index: '', width: 85, label: "单位成本", align:"right" },
				{ name: 'rk_jine', index: '', width: 85, label: "成本", align:"right" },
                { name: 'ck_num', index: '', width: 85, label: "出库数量", align:"center" },
				{ name: '', index: '', width: 85, label: "基本单位数量", align:"center" },
				{ name: 'ck_price', index: '', width: 85, label: "单位成本", align:"right" },
				{ name: 'ck_jine', index: '', width: 85, label: "成本", align:"right" },
                { name: 'jc_num', index: '', width: 85, label: "基本单位数量", align:"center" },
				{ name: 'jc_price', index: '', width: 85, label: "单位成本", align:"right" },
				{ name: 'jc_jine', index: '', width: 85, label: "成本", align:"right"}
				
			],
			rowNum: 10,
			rowList: [10, 20, 30],
			sortname: 'id',
			sortorder: "desc",
			pagerpos: "left",//分页位置

			pgbuttons: true,//翻页按钮
			pagination: true,
			altRows: false,
			gridview: !0,
			shrinkToFit: !1,
			cellLayout: 8,
			autowidth: !0,
			pager: "#page",
			viewrecords: !0,
			cmTemplate: {
				sortable: !1,
				title: !1
			},
			loadError: function (t, e, i) {
				parent.Public.tips({
					type: 1,
					content: "操作失败了哦，请检查您的网络链接！"
				})
			},
            // 合计
			footerrow: true,
			gridComplete: function () {
				var rk_nums = parseFloat($("#grid").getCol('rk_num', false, 'sum')).toFixed(2);
				var rk_jines = parseFloat($("#grid").getCol('rk_jine', false, 'sum')).toFixed(2);
				var ck_nums = parseFloat($("#grid").getCol('ck_num', false, 'sum')).toFixed(2);
				var ck_jines = parseFloat($("#grid").getCol('ck_jine', false, 'sum')).toFixed(2);
				var jc_nums = parseFloat($("#grid").getCol('jc_num', false, 'sum')).toFixed(2);
				var jc_jines = parseFloat($("#grid").getCol('jc_jine', false, 'sum')).toFixed(2);
				$("#grid").footerData('set', { "goods_category_name": '合计：', rk_num:rk_nums, rk_jine:rk_jines, ck_num:ck_nums, ck_jine:ck_jines, jc_num: jc_nums,jc_jine:jc_jines });
			
				// 合并合计单元格
				var $footRow = $("#grid").closest(".ui-jqgrid-bdiv").next(".ui-jqgrid-sdiv").find(".footrow");
				$footRow.find('>td[aria-describedby="grid_goods_category_name"], >td[aria-describedby="grid_sn"], >td[aria-describedby="grid_name"], >td[aria-describedby="grid_code"], >td[aria-describedby="grid_model"]').css("border-right-color", "transparent");
			},
		});

		// 合并表头单元格
		$("#grid").jqGrid('setGroupHeaders', {
			useColSpanStyle: true,
			groupHeaders: [
				{ startColumnName: 'rk_num', numberOfColumns: 4, titleText: '入库' },
				{ startColumnName: 'ck_num', numberOfColumns: 4, titleText: '出库' },
				{ startColumnName: 'jc_num', numberOfColumns: 3, titleText: '结存' }
			]
		});

		var headH = 0;  //顶部搜索是否展开（1：展开，0：未展开）
		$("#conditions-trigger").click(function () {
			if (headH == 0) {
				headH = 1;
				$("#filterItems").css({ "height": "auto" });
				$(this).html("&nbsp;收起条件<b class='act'></b>");
				// 设置表格高度
				$("#grid").setGridHeight($(window).height()-260-$("#filter-menu").height()+"px");
			} else {
				headH = 0;
				$("#filterItems").css({ "height": "44px" });
				// $("#filterItems").animate({height:'44px'});
				$(this).html("&nbsp;更多条件<b></b>");
				// 设置表格高度
				$("#grid").setGridHeight($(window).height()-260-$("#filter-menu").height()+"px");
			}
		});
		

		// 获取当前日期
        var myDate = new Date;
        var year = myDate.getFullYear(); //获取当前年
        var mon = myDate.getMonth() + 1; //获取当前月
        var date = myDate.getDate(); //获取当前日
        // console.log(year + '-' + mon + '-' + date)
        if (mon < 10) {
        mon = "0" + mon;
        }
        if (date < 10) {
        date = "0" + date;
        }
        $("#startdate").val(year + '-' + mon + '-01');
        $("#enddate").val(year + '-' + mon + '-' + date);

	});



	function actions(cellvalue, options, rowObject) {
		return '<div class="operating"><span class="ui-icon ui-icon-pencil" onclick="lopen(\'edit.html?id=' + rowObject.id + '\',\'编辑\',\'400px\',\'300px\')">修改</span> <span class="ui-icon ui-icon-trash" onclick="del(' + rowObject.id + ')">删除</span></div>';
	}
    
    //仓库选择框外点击则隐藏
    $(document).mouseup(function (e) {
        // if(e.target.id!="goods_type"){
            var con = $("#filterSelectBox");   // 设置目标区域
            if (!con.is(e.target) && con.has(e.target).length === 0) {
                 $("#filterSelectBox").hide();
            }
        // } 
    });


	// 顶部搜索下拉选择窗口(商品类别)
	function chooseFilter() {
		var top = $("#goods_type .ui-tree-wrap").offset().top;
		var left = $("#goods_type .ui-tree-wrap").offset().left;
		var width = $("#goods_type .ui-tree-wrap").width();
		$("#filterSelectBox").toggle();
		$("#filterSelectBox").css({ "top": (top + 30) + "px", "left": (left) + "px", "minWidth": width + "px" });
	}

</script>

<script type="text/javascript">
	function chooseSupplier() {
		layer.open({
			type: 2,
			title: "选择销售人员",
			shadeClose: true,
			shade: 0.3,
			maxmin: false, //开启最大化最小化按钮
			area: ['775px', '510px'],
			fixed: false, //不固定
			btn: ['确定', '取消'],
			content: "/admin/basic/choose_customer.html",
			btn1: function (index, layero) {
				var body = layer.getChildFrame('body', index);
				var supplierid = body.find('input[name="goodid"]:checked').val();

				if (supplierid == '' || supplierid == null) {
					layer.msg("请选择供应商");
					return false;
				} else {
					//获取商品信息
					$.get("/admin/basic/one_customer.html", { id: supplierid }, function (data, state) {
						if (data.status == 1) {
							$("#supplierAuto").val(data.info.sn + " " + data.info.name);
							$('#supplierid').val(data.info.id);
							layer.close(index);
						} else {
							layer.msg("获取商品信息失败");
						}
					})
				}
				layer.close(index);
				return false;
			},
			btn4: function (index, layero) {
				layer.close(index);
				return false;
			}
		})
	}

	function pre_choose_goods() {
		layer.open({
			type: 2,
			title: "选择商品",
			shadeClose: true,
			shade: 0.3,
			maxmin: false, //开启最大化最小化按钮
			area: ['900px', '650px'],
			fixed: false, //不固定
			btn: ['确定', '取消'],
			content: "/admin/basic/choose_goods.html",
			btn1: function (index, layero) {
				var body = layer.getChildFrame('body', index);
				var goods_id = body.find('input[name="goodid"]:checked').val();

				if (goods_id == '' || goods_id == null) {
					layer.msg("请选择商品");
					return false;
				} else {
					//获取商品信息
					$.get("/admin/basic/one_goods.html", { id: goods_id }, function (data, state) {
						if (data.status == 1) {
							$("#goods input").val(data.info.sn + " " + data.info.name);
							$('#goodsid').val(data.info.id);
							layer.close(index);
						} else {
							layer.msg("获取商品信息失败");
						}
					})
				}
				layer.close(index);
				return false;
			},
			btn4: function (index, layero) {
				layer.close(index);
				return false;
			}
		})
	}

	function chooseStore() {
		layer.open({
			type: 2,
			title: "选择仓库",
			shadeClose: true,
			shade: 0.3,
			maxmin: false, //开启最大化最小化按钮
			area: ['775px', '510px'],
			fixed: false, //不固定
			btn: ['确定', '取消'],
			content: "/admin/basic/choose_store.html",
			btn1: function (index, layero) {
				var body = layer.getChildFrame('body', index);
				var storeid = body.find('input[name="goodid"]:checked').val();
				console.log(storeid);
				if (storeid == '' || storeid == null) {
					layer.msg("请选择仓库");
					return false;
				} else {
					//获取仓库信息
					$.get("/admin/basic/one_store.html", { id: storeid }, function (data, state) {
						if (data.status == 1) {
							$("#store input").val(data.info.bh + " " + data.info.name);
							$('#storeid').val(data.info.id);
							layer.close(index);
						} else {
							layer.msg("获取仓库信息失败");
						}
					})
				}
				layer.close(index);
				return false;
			},
			btn4: function (index, layero) {
				layer.close(index);
				return false;
			}
		})
	}
</script>

{include file="admin@public/footer"/}